/*
 * @Author: your name
 * @Date: 2022-03-17 13:38:32
 * @LastEditTime: 2022-03-28 18:31:03
 * @LastEditors: Please set LastEditors
 * @FilePath: \VUE\app\src\store\home\index.js
 */

import { reqCategoryList, reqBannerList, reqFloorList } from "@/api";

//仓库存储数据的
const state = {
    //三级分类
    categoryList: [],
    //轮播图
    bannerList: [],
    //获取floor 家用电器
    floorList:[],
};
//修改state的唯一手段
const mutations = {
    CATEGORYLIST(state, categoryList) {
        state.categoryList = categoryList
    },
    GETBANNERLIST(state, bannerList) {
        state.bannerList = bannerList
    },
    GETFLOORLIST(state,floorList){
        state.floorList = floorList
    }
};
//处理action，书写业务逻辑，异步处理
const actions = {
    //通过API里面的接口函数调用，向服务器发请求，获取数据
    async categoryList({ commit }) {
        let result = await reqCategoryList()
        if (result.code == 200) {
            commit('CATEGORYLIST', result.data)
        }
    },

    //获取banner数据
    async getBannerList({ commit }) {
        let result = await reqBannerList()
        if (result.code == 200) {
            commit('GETBANNERLIST', result.data)
        }
    },
    //获取floor数据
    async getFloorList({ commit }) {
        let result = await reqFloorList()
        if (result.code == 200) {
            commit('GETFLOORLIST', result.data)
        }
    }
};

//getters理解为计算属性让组件获取仓库数据更方便
const getters = {};



//暴露一个store实例
export default {
    state,
    mutations,
    actions,
    getters

}
